/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package VLSObjects;

import DBConnection.*;
import java.sql.*;

public class ExpenseManager {
    
    public boolean addExpense(Expense newExpense)
    {
        boolean result = false;

         try{
            //opens db connection
            ConnectionFactory myFactory = ConnectionFactory.getFactory();
            Connection conn = myFactory.getConnection();

            int i = 1;

            //SQL Query
            PreparedStatement pstmt = conn.prepareStatement("INSERT INTO expense ( expense_date, expense_type, expense_amount) VALUES(?,?,?)");

            //include parameters
            //pstmt.setInt(i++, newExpense.getExpenseID());
            pstmt.setString(i++, newExpense.getExpenseDate());
            pstmt.setString(i++, newExpense.getExpenseType());
            pstmt.setInt(i++, newExpense.getExpenseAmount());

            //execute query
            pstmt.executeUpdate();

            //close DB connection
            conn.close();

            result=true;
            }
            catch(SQLException e)
            {
               e.printStackTrace();
            }
            return result;
    }
    
}
